/*
package com.whirl.ai_ml;

import cn.hutool.core.util.NumberUtil;
import com.whirl.controller.ForecastController;
import ml.dmlc.xgboost4j.java.Booster;
import ml.dmlc.xgboost4j.java.DMatrix;
import ml.dmlc.xgboost4j.java.XGBoost;
import ml.dmlc.xgboost4j.java.XGBoostError;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.math.BigDecimal;

import static com.whirl.util.Constants.MLData_PATH;

*/
/**
 * @author xw
 * @date 2022/8/17 11:09
 *//*

public class XGBoostPredict {
    public static void predict(String path) throws XGBoostError {
        // 加载模型
//        Booster booster = XGBoost.loadModel(MLData_PATH + "load_rate/model/xgb_model.model");
        Booster booster = XGBoost.loadModel("model/xgb_model.model");
        DMatrix temper_humidity_mat = new DMatrix(path);
        // 预测结果
        System.out.print("预测值： ");
        float[][] predicts = booster.predict(temper_humidity_mat);
        for (int i = 0; i < predicts.length; i++) {
            for (int j = 0; j < predicts[0].length; j++) {
                BigDecimal retain2 = NumberUtil.round(predicts[i][j], 2);
                predicts[i][j] = retain2.floatValue();
                System.out.print(predicts[i][0] + "  ");  // 写[i][j]结果也一样的，因为 predicts[0].length = 1
            }
        }
    }

    public static void main(String[] args) throws XGBoostError, IOException {
        // 写入文件位置
        String filePath = "src/main/java/com/whirl/ai_ml/ai_predict.txt";

        // 调用天气接口，获取特征参数并整理好为libsvm格式写入文件
        ForecastController forecastController = new ForecastController();
        forecastController.getForecastAndSetWeatherInFile(filePath);

        // 进行预测并输出结果到控制台
        predict(filePath);
    }
}
*/
